package com.lagou.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/auth")
public class AuthController {

    @RequestMapping(value = "/toLogin", method = RequestMethod.GET)
    public String toLoginPage() {
        return "jsp/login";
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public String login(HttpServletRequest req, HttpServletResponse resp,
                        String username, String password) {
        if("admin".equals(username) && "admin".equals(password)) { // 登录成功
            req.getSession().setAttribute("username", username);
            return "redirect:/resume/listpage";
        }else {
            return "login";
        }
    }

    @RequestMapping(value = "/logout")
    public String logout(HttpServletRequest req) {
        req.getSession().invalidate();
        return "login";
    }
}
